#include "place.h"

using namespace std;

Place::Place(int pcount, const char* placeName) {
    name = new char[strlen(placeName) + 1];
    strcpy(name, placeName);
    peopleCount = pcount;
}

Place::Place(const Place& a) {
    name = new char[strlen(a.name) + 1];
    strcpy(name, a.name);
    peopleCount = a.peopleCount;
}

Place::~Place() {
    std::cout << "free place\n";
    delete[] name;
}

void Place::print() {
    for (int i = 0; i < Place::count; i++) {
        Place::list[i]->out();
    }
}

void Place::Add() {
    auto** temp = new Place * [count];
    for (int i = 0; i < count; i++) {
        temp[i] = list[i];
    }
    list = new Place * [count + 1];
    list[count] = this;
    for (int i = 0; i < count; i++) {
        list[i] = temp[i];
    }
    count++;
}

void Place::freeList() {
    delete[] list;
}

Place& Place::operator=(const Place& a) {
    if (this == &a) {
        return *this;
    }
    delete[] name;
    name = new char[strlen(a.name) + 1];
    strcpy(name, a.name);
    peopleCount = a.peopleCount;
    return *this;
}
